package com.cskaoyan.controller.admin.marketmanagement;

import com.cskaoyan.anno.ValidAnno;
import com.cskaoyan.bean.MarketBrand;
import com.cskaoyan.bean.bo.admin.brand.BrandListBo;
import com.cskaoyan.bean.common.BaseRespVo;
import com.cskaoyan.bean.vo.admin.brand.BrandListVo;
import com.cskaoyan.service.admin.brand.BrandService;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.BindingResult;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.validation.Valid;

/**
 * Created with IntelliJ IDEA.
 *
 * @Author: bwj
 * @Date: 2022/09/07/9:10
 * @Description:
 */
@RestController
@RequestMapping("admin/brand")

public class BrandController {
    @Autowired
    BrandService brandService;

    /**
    * @Author: 宾文杰 @Description: 根据当前页面、限制数和排序条件获取全部品牌制造商信息 @Date: 2022/9/7
    */
    @RequiresPermissions("admin:brand:list")
    @RequestMapping("list")
    @ValidAnno
    public BaseRespVo<BrandListVo> brandList(@Valid BrandListBo listBo, BindingResult bindingResult){
        BrandListVo brandListVo = brandService.brandList(listBo.getPage(), listBo.getLimit(), listBo.getSort(), listBo.getOrder(),listBo.getId(),listBo.getName());
        return BaseRespVo.ok(brandListVo);
    }

    /**
    * @Author: 宾文杰 @Description: 添加品牌商信息 @Date: 2022/9/7
    */
    @RequestMapping("create")
    public BaseRespVo<MarketBrand> brandCreate(@RequestBody MarketBrand marketBrand){
        MarketBrand brandCreate = brandService.brandCreate(marketBrand);
        return BaseRespVo.ok(brandCreate);
    }

    /**
    * @Author: 宾文杰 @Description: 更新品牌商信息 @Date: 2022/9/7
    */
    @RequestMapping("update")
    public BaseRespVo<MarketBrand> brandUpdate(@RequestBody MarketBrand marketBrand){
        MarketBrand brandUpdate = brandService.brandUpdate(marketBrand);
        return BaseRespVo.ok(brandUpdate);
    }

    /**
    * @Author: 宾文杰 @Description: 删除品牌商信息 @Date: 2022/9/7
    */
    @RequestMapping("delete")
    public BaseRespVo<String> brandDelete(@RequestBody MarketBrand marketBrand){
        brandService.brandDelete(marketBrand);
        return BaseRespVo.ok(null);
    }

}
